﻿using UnityEngine;

namespace CinemaDirector
{
    /// <summary>
    /// The ActorTrackGroup maintains an Actor and a set of tracks that affect 
    /// that actor over the course of the Cutscene.
    /// </summary>
    [TrackGroupAttribute("Actor Track Group", TimelineTrackGenre.ActorTrack)]
    public class ActorTrackGroup : TrackGroup
    {
        //设置Actor的prefab，用于检测参数是否正确，如节点路径。不会用于运行时。
        [SerializeField]
        public Transform DebugActor;

        [SerializeField]
        private Transform actor;

        [SerializeField]
        public string actorPath = "";

        [SerializeField]
        public string actorName;

        [SerializeField]
        public bool saveActorToPrefab = true;

        /// <summary>
        /// The Actor that this TrackGroup is focused on.
        /// </summary>
        public Transform Actor
        {
            get { return actor; }
            set { actor = value; }
        }

        public override void RecordAffectObjectPath()
        {
            if (actor != null)
                actorPath = actor.GetFullHierarchyPath();
        }

        public override void FixAffectObjectPath()
        {
            if (actorPath != "")
            {
                var go = U3DHelp.FindChildInGameObject(actorPath);
                if (go == null)
                {
                    Debug.LogWarning("Can not fix actor path " + actorPath);
                    return;
                }
                actor = go.transform;
            }
        }
    }
}